package org.lanqiao.api.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.PageModel;
import org.lanqiao.pojo.ProductPOJO;
import org.lanqiao.pojo.UserPOJO;
import org.lanqiao.service.AdminServiceImpl;

/**
 * 修改商品
 * Servlet implementation class AmendProductServlet
 */
@WebServlet("/api/admin/AmendProductServlet")
public class AmendProductServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		/**
		 * 获取参数
		 */
			String pageSize="10";
			String pageNum=request.getParameter("page");
			String Id=request.getParameter("Id");
			String name=request.getParameter("Productname");		
			String code=request.getParameter("Productcode");
			String price=request.getParameter("Price");		
			String sale=request.getParameter("Sale");
			String status=request.getParameter("Status");
			
			ProductPOJO pro=new ProductPOJO();
			pro.setProductId(Id);
			pro.setProductName(name);
			pro.setProductCode(code);
			pro.setPrice(price);
			pro.setSale(sale);
			pro.setStatus(status);
			/**
			 * 调用修改用户方法
			 */
			AdminServiceImpl abc=new AdminServiceImpl();
			JsonResult result=null;
			try {
				int model=abc.amendProducts(pro);
				if(model>0){
					result=new JsonResult("修改成功",Constants.STATUS_SUCCESS);
				}else {
					result=new JsonResult("修改错误",Constants.STATUS_UNFOUND);
				}
			} catch (Exception e) {
				result=new JsonResult("修改异常",Constants.STATUS_FAILURE);
			}
			JsonResultWriter.writer(response, result);;
	}
}
